require('./PageNbtzlist.styl');

import {Avatar, Boxs, Group, Scroller, ScrollList, SearchBar, Tab} from 'saltui';
import {Component} from 'react';
import reactMixin from 'react-mixin';
import Store from './store';
import Reflux from 'reflux';
import {PropTypes} from "prop-types";
import {is} from 'immutable'
import Actions from './actions'

const HBox = Boxs.HBox;
const Box = Boxs.Box;


class Page extends Component {


  constructor(props) {
    super(props);
  }


  componentWillMount() {
    Actions.fetchList();
    dd.device.notification.hidePreloader();

  }

  render() {


    return (
      <div className="nbtzlist">
        <Group>
          <Group.Head>
            内部通知列表
          </Group.Head>
          <Scroller className="page" mouseWheel>

            {this.state.nbtzlist.items.map((item, k) => {

              return <Group.List>
                <div className='nbtz-t-list-wrap' key={k} onClick={() => {
                  dd.biz.util.openLink({
                    url: item.url,
                  });
                }}>
                  <Box>

                    <p className='nbtz-t-list-title t-omit2'>
                      <span>{item.title}</span></p>

                    <p className='jcjl-t-list-title'>
                     <span
                       style={{
                         paddingRight: '5px',
                         color: '#5E97F6',
                         fontSize: '13px',
                         float: 'right'
                       }}>{item.gmtCreate}</span>
                    </p>
                  </Box>

                </div>
              </Group.List>
            })}
          </Scroller>
        </Group>
      </div>
    )
      ;
  }

  shouldComponentUpdate(nextProps = {}, nextState = {}) {
    const thisProps = this.props || {},
      thisState = this.state.nbtzlist || {};

    if (Object.keys(thisProps).length !== Object.keys(nextProps).length ||
      Object.keys(thisState).length !== Object.keys(nextState).length) {
      return true;
    }

    for (const key in nextProps) {
      if (thisProps[key] !== nextProps[key] || !is(thisProps[key], nextProps[key])) {
        console.log(thisProps[key], nextProps[key]);
        return true;
      }
    }

    for (const key in nextState) {
      if (thisState[key] !== nextState[key] || !is(thisState[key], nextState[key])) {
        return true;
      }
    }
    return false;
  }
}

reactMixin.onClass(Page, Reflux.connect(Store, "nbtzlist"));

export default Page;
